from math import factorial


def binomial_coefficient(n, k):
    """
    使用math库的阶乘函数计算组合数 C(n,k) 的值
    :param n:
    :param k:
    :return:
    """
    return factorial(n) // (factorial(n - k) * factorial(k))

def binomial_expansion(a, b, n):
    terms = []
    result = []
    for i in range(0, n + 1):
        coff = binomial_coefficient(n, i)
        temp = coff * pow(a,n-i) * pow(b,i)
        terms.append(coff)
        result.append(temp)

    print(terms)
    print(result)



if __name__ == '__main__':
    # print(binomial_coefficient(4, 2))
    binomial_expansion(2, 3, 5)

